Skip to content

fix: get invite proposal null issue - #1655

Merged
yoganandaness merged 5 commits into
developfrom
copilot/fix-properties-reading-error
Jul 21, 2026
Merged

fix: get invite proposal null issue#1655
yoganandaness merged 5 commits into
developfrom
copilot/fix-properties-reading-error

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

A GraphQL query resolving proposal on registrationInvites threw TypeError: Cannot read properties of undefined (reading 'proposal_id') whenever an invite had no matching proposal row.

Root cause

ProposalDataSource.getInvitedProposal guarded on the query result with proposals ? ... : null. A Knex select().where() always returns an array (never undefined), so an empty result still passed the truthy check and handed proposals[0] (undefined) to createInvitedProposalObject, which dereferenced record.proposal_id.

Changes

  • ProposalDataSource.ts: guard on the first element rather than the array so an empty result returns null.
return proposals?.[0] ? createInvitedProposalObject(proposals[0]) : null;

@yoganandaness yoganandaness changed the title Fix crash in getInvitedProposal when no invite matches fix: get invite proposal null issue Jul 20, 2026
@yoganandaness

Copy link
Copy Markdown
Contributor

@copilot Here is my suggestion

async getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> {
return await database
.select(
'proposals.proposal_id',
'proposer.firstname as proposer_name',
'proposals.abstract',
'proposals.title'
)
.from('co_proposer_claims')
.join('proposals', {
'co_proposer_claims.proposal_pk': 'proposals.proposal_pk',
})
.join('users as proposer', {
'proposals.proposer_id': 'proposer.user_id',
})
.where('invite_id', inviteId)
.first()
.then((proposal: InvitedProposalRecord) => {
return proposal ? createInvitedProposalObject(proposal) : null;
});
}

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Here is my suggestion

async getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> {
...

Applied in 33426eb — refactored getInvitedProposal to use .first() with the .then() guard as suggested.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Here is my suggestion

async getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> {
return await database
.select(
'proposals.proposal_id',
'proposer.firstname as proposer_name',
'proposals.abstract',
'proposals.title'
)
.from('co_proposer_claims')
.join('proposals', {
'co_proposer_claims.proposal_pk': 'proposals.proposal_pk',
})
.join('users as proposer', {
'proposals.proposer_id': 'proposer.user_id',
})
.where('invite_id', inviteId)
.first()
.then((proposal: InvitedProposalRecord) => {
return proposal ? createInvitedProposalObject(proposal) : null;
});
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already implemented in commit 33426ebgetInvitedProposal uses .first() with the .then() guard exactly as suggested.

@yoganandaness
yoganandaness marked this pull request as ready for review July 20, 2026 11:54
@yoganandaness
yoganandaness requested a review from a team as a code owner July 20, 2026 11:54
@yoganandaness
yoganandaness requested review from Bhaswati1148 and removed request for a team July 20, 2026 11:54
Copilot AI requested a review from yoganandaness July 20, 2026 11:55
@yoganandaness
yoganandaness requested review from TCMeldrum and zacharyjhankin and removed request for Bhaswati1148 July 20, 2026 11:56
@zacharyjhankin

zacharyjhankin commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Could also just do:

return proposals?.[0] ? createInvitedProposalObject(proposals[0]) : null;

Edit: I mean I do slightly prefer that but idm. approved

@yoganandaness
yoganandaness enabled auto-merge (squash) July 21, 2026 11:13
@yoganandaness
yoganandaness merged commit cc79ff4 into develop Jul 21, 2026
21 checks passed
@yoganandaness
yoganandaness deleted the copilot/fix-properties-reading-error branch July 21, 2026 11:46
shivoomiess added a commit that referenced this pull request Jul 27, 2026
Resolves a conflict in getInvitedProposal. develop (#1655) fixed the
null handling with .first(); this branch had widened the query to
cover data_access_claims alongside co_proposer_claims.

Kept both: the union subquery from this branch, returning through
.first().then(...) as on develop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants